package com.tanhua.server.controller;

import com.tanhua.model.vo.*;
import com.tanhua.server.service.TanhuaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 获取今日佳人
     *
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest recommendUser = tanhuaService.todayBest();

        return ResponseEntity.ok(recommendUser);
    }

    /**
     * 佳人信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long id) {
        TodayBest todayBest = tanhuaService.personalInfo(id);
        return ResponseEntity.ok(todayBest);
    }

    /**
     * 推荐朋友
     *
     * @param recommendUserQueryParam
     * @return
     */
    @GetMapping("/recommendation")
    public ResponseEntity RecommenDation(RecommendUserQueryParam recommendUserQueryParam) {
        PageResult<TodayBest> result = tanhuaService.recommenDation(recommendUserQueryParam);
        return ResponseEntity.ok().body(result);
    }

    /**
     * 获取陌生人问题
     *
     * @param userId
     * @return
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestParam Long userId) {
        String questions = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }

    /**
     * 探花
     *
     * @return
     */
    @GetMapping("/cards")
    public ResponseEntity Cards() {
        List<CardsVo> vo = tanhuaService.getCards();
        return ResponseEntity.ok(vo);
    }

    /**
     * 右滑喜欢
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity loveUser(@PathVariable Long id) {
        tanhuaService.loveUser(id, true);
        return ResponseEntity.ok(null);
    }

    /**
     *     左滑不喜欢
     * @param id
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity notLoveUser(@PathVariable Long id) {
        tanhuaService.loveUser(id, false);
        return ResponseEntity.ok(null);
    }

    /**
     * 回复陌生人问题
     *
     * @param params
     * @return
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestBody Map<String, Object> params) {
        tanhuaService.sendStrangerQuestions(params);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜索附近的人
     *
     * @param gender
     * @param distance
     * @return
     */
    @GetMapping("/search")
    private ResponseEntity findSearch(String gender, Long distance) {
        List<NearUserVo> vo = tanhuaService.findSearch(gender, distance);
        return ResponseEntity.ok(vo);
    }
}
